package com.situ.feemanagement.controller;

import com.situ.feemanagement.pojo.Patient;
import com.situ.feemanagement.pojo.query.PatientQuery;
import com.situ.feemanagement.service.IPatientService;
import com.situ.feemanagement.util.PageResult;
import com.situ.feemanagement.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.expression.spel.ast.Literal;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/patient")
public class PatientController {

    @Autowired
    private IPatientService patientService;

    @RequestMapping("/selectAll")
    public List<Patient> selectAll() {
        return patientService.selectAll();
    }

    @RequestMapping("/selectByPage")
    public PageResult<Patient> selectByPage(PatientQuery patientQuery) {
        return patientService.selectByPage(patientQuery);
    }

    @RequestMapping("/deleteById")
    public Result deleteById(String id) {
        patientService.deleteById(Integer.parseInt(id));
        return Result.ok("删除成功");
    }

    @RequestMapping("/deleteAll")
    public Result deleteAll(String[] ids) {
        patientService.deleteAll(ids);
        return Result.ok("删除成功");
    }

    @RequestMapping("/add")
    public Result add(Patient patient) {
        patientService.add(patient);
        return Result.ok("添加成功");
    }

    @RequestMapping("/selectById")
    public Result selectById(String id) {
        Patient patient = patientService.selectById(Integer.parseInt(id));
        return Result.ok(patient);
    }

    @RequestMapping("/update")
    public Result update(Patient patient) {
        patientService.update(patient);
        return Result.ok("更新成功");
    }
}
